<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
        <button @click="add">添加学生</button>
        <button @click="del">删除学生</button>
        <table border='1' width='50%' style='border-collapse: collapse;'>
            <tr>
                <th>班级</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
            </tr>
            <tr align="center" v-for="student in students">
                <td>{{student.grade}}</td>
                <td>{{student.name}}</td>
                <td>{{student.gender}}</td>
                <td>{{student.age}}</td>
            </tr>
        </table>
    </div>
    <script>
        const app=new Vue({
            el:'#app',
            data:{
                students:[{
                    grade:'1',
                    name:'李四',
                    gender:'男',
                    age:25,
                },{
                    grade:'2',
                    name:'李四',
                    gender:'男',
                    age:25,
                },{
                    grade:'3',
                    name:'李四',
                    gender:'男',
                    age:25,
                },{
                    grade:'4',
                    name:'李四',
                    gender:'男',
                    age:25,
                },]
            },
            methods:{
                add(){
                        var stu={
                        grade:'5',
                        name:'张三',
                        gender:'男',
                        age:25,
                    }
                    this.students.push(stu)
                },
                del(){
                    this.students.pop()
                }
            }
        });
    </script>
</body>
</html>